(function() {
	var $ = require(L('$')), _ = require(L('_'));

	var win = Ti.UI.createWindow({
		width : Ti.UI.FILL,
		height : Ti.UI.FILL,
	});

	var ui = $.layout('ipad/home');
	win.add(ui.wrapper);

	var currentTranslation = {
		x : 0.0,
		y : 0.0
	};
	var lastTranslation = {
		x : 0.0,
		y : 0.0
	};
	function updateTransform() {
		var transform = Ti.UI.create2DMatrix();
		transform.tx = Math.min(Math.max(lastTranslation.x + currentTranslation.x, 0), 320);
		ui.view.transform = transform;
	};
	$.on('pan', ui.view, function(e) {
		currentTranslation.x = e.translation.x;
		updateTransform();
	});
	$.on('panend', ui.view, function(e) {
		var x = lastTranslation.x + currentTranslation.x;
		var leftWidth = 320;
		x = x > leftWidth ? leftWidth : (x < leftWidth / 2 ? 0 : leftWidth);
		ui.mask.visible = x == 0 ? false : true;
		lastTranslation.x = x;
		currentTranslation.x = 0.0;
		currentTranslation.y = 0.0;
		updateTransform();
	});
	win.open({
		modal : false,
		modalTransitionStyle : Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_VERTICAL,
		modalStyle : Ti.UI.iPhone.MODAL_PRESENTATION_FULLSCREEN,
		navBarHidden : true
	});
})();

